package cn.juque.datapipeline.quartz;

import org.quartz.spi.TriggerFiredBundle;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.scheduling.quartz.AdaptableJobFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author juque
 * @version 1.0.0
 * <ul>
 *     <li>SpringJobFactory</li>
 *     <li>解决job中service注入为空的问题。</li>
 * </ul>
 * @date 2023-04-08 21:58:32
 **/
@Component
public class SpringJobFactory extends AdaptableJobFactory {

    @Resource
    private AutowireCapableBeanFactory autowireCapableBeanFactory;

    @Override
    protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
        Object jobInstance = super.createJobInstance(bundle);
        // 进行注入
        this.autowireCapableBeanFactory.autowireBean(jobInstance);
        return jobInstance;
    }
}
